package solver;

import java.util.Iterator;

import ilog.concert.IloException;
import ilog.concert.IloNumVar;
import ilog.cplex.IloCplex;
import tools.Vector;
import uncertainty.UncertaintySet;


/**
 * @class VariableMapping
 * 
 * This class represents a mapping for the variables used to build up 
 * the diferrent problems in this code.
 * 
 * @author Marcio Costa Santos
 * @see VariableMapping
 */
public class VariableMappingDR extends VariableMapping {

	/**
	 * @Constructor
	 * 
	 * @param dim
	 * @param k
	 * */
	public VariableMappingDR(int dim, int k) {
		super(dim, k);
	}

	@Override
	/**
	 * @method initialize
	 * 
	 * @param UncertaintySet us
	 * @param  Ilocplex cplex
	 * */
	public void initialize(UncertaintySet us, IloCplex cplex)throws IloException {
		Iterator<Vector<Double>> it = us.extremePoints();
		Vector<Double> elem;
		StrucRecXiT data;
		IloNumVar[][] var = new IloNumVar[n][];
		int min;
		
		for(int i = 0; i < n; i++){
			min = i + 1 - k >= 0? i-k : 0;
			var[i] = new IloNumVar[min + 1 < n + 1? min + 1 : n + 1];
			for(int j = 0; j < var[i].length; j++){
				var[i][j] = cplex.numVar(Double.MIN_VALUE, Double.MAX_VALUE);
			}
		}
		
		while(it.hasNext()){
			elem = it.next();
			for(int i = 0; i < n; i++){
				data = new StrucRecXiT(elem.getProjection(i - k), i);
				if(!map.contains(data)){
					map.put(data, var[i]);
				}
			}
			it.remove();
		}
		
	}

}
